package com.example.service.impl;

import com.example.event.MyEvent;
import com.example.service.ListenerMyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;

/**
 * Created by IntelliJ IDEA2021.3
 *
 * @Author: Tenghw
 * @Date: 2022/09/26  17:04
 * @Description:
 */
@Slf4j
@Service("listenerMyService")
public class ListenerMyServiceImpl implements ListenerMyService, ApplicationEventPublisherAware {
    private ApplicationEventPublisher applicationEventPublisher;

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        log.warn("springboot启动时自动触发...");
        this.applicationEventPublisher = applicationEventPublisher;
    }

    @Override
    public void testListenerPublisher(Object obj) {
        log.warn("进入service层的testListenerPublisher()方法...");
        log.warn("请求参数为：{}", obj);
        //发布事件
        applicationEventPublisher.publishEvent(new MyEvent(obj));
    }
}
